package com.neusoft.neuiotms.dcam.common.model;

import com.neusoft.bizcore.web.jpa.model.AbstractModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@ToString
@Entity
@org.hibernate.annotations.Table(appliesTo = "neuiot_institutions", comment = "单位管理表")
@Table(name = "neuiot_institutions")
public class DcamInstitutions  extends AbstractModel {
    private static final long serialVersionUID = 1L;

    /** 单位名称 */
    @NotBlank(message = "单位名称不能为空")
    @Length(max = 255, message = "单位名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '单位名称'")
    private String name;

    /** 单位编码 */
    @Length(max = 255, message = "单位编码不能超过{max}位")
    @Column(length = 255, nullable = false, unique = true)
    @Comment("varchar(255) NOT NULL COMMENT '单位编码'")
    private String code;

    /** 关联驻场人员（一线运维人员） */
    @OneToMany(mappedBy = "institutions", cascade = {CascadeType.ALL })
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<DcamResidentUser> residents = new ArrayList<>();

    /** 关联机动人员 */
    @OneToMany(mappedBy = "institutions", cascade = {CascadeType.ALL })
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<DcamInstitutionsUser> users = new ArrayList<>();
}
